
package org.open.sharedRadar;

import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AddFriend extends Dialog {
		
	private EditText userTxt;	
	private Activity activity;
	private ListActivity lista;		
	
	public AddFriend(Context context) {
	    super(context);	    
	}
	public void setParentActivity(Activity activity_)
	{
		this.activity = 	activity_;	
	}
	public void exitActivity()
	{		
		this.activity.finish();
		
	}
	public void setLista(ListActivity lista_)
	{		
		this.lista = lista_;
		
	}
	private class OKListener implements android.view.View.OnClickListener {

		public void onClick(View arg0) {
			try
			   {
				WebServiceHandler handler = new WebServiceHandler();
				if(userTxt.getText() == null || userTxt.getText().toString().equals(""))
				{
					Toast.makeText(lista, "Introduceti un id!", Toast.LENGTH_SHORT).show();					
				}
				else
				{
					String user = userTxt.getText().toString();
					String result = handler.sendFriendRequest(user);
					Toast.makeText(lista, result, Toast.LENGTH_SHORT).show();					                
				}
				dismiss();
			   }
			   catch (Exception aE)
			   {
			       aE.printStackTrace ();;
			   }
		}
    }	
	@Override
       public void onCreate(Bundle savedInstanceState)
       {
		   super.onCreate(savedInstanceState);
	       setContentView(R.layout.confirmfriend);
	       setTitle("Confirmare");
	       Button buttonConfirm = (Button) findViewById(R.id.confirmBtn);
	       buttonConfirm.setOnClickListener(new OKListener()); 	                
	       userTxt =  (EditText) findViewById(R.id.userIdTxt);  
	       //userTxt.setText(user);	       
      }
}